<#include "../base.ftl"/>
<#macro css>

</#macro>

<#macro js>

</#macro>

<#macro title>
广大物流云平台
</#macro>
<#macro script>

	function initJqGridHideBtn(){
		$("#add_gridTable").hide();
        $("#edit_gridTable").hide();
        $("#del_gridTable").hide();
	}
	function  initJqGridHideDtlBtn(){
		
		$("#edit_gridSchedulingTable").hide();
        $("#del_gridSchedulingTable").hide();
        $("#add_gridSchedulingTable").hide();
		
	}
     var setting = {
            async: {
                enable: true,
                url: '${request.contextPath}/admin/shipVoyageTree.action',
                datatype : 'json',
                autoParam:["id","name","level","flag"]
            },
            data: {
                simpleData: {
                       enable: true
                }
            },
            callback:{
                onNodeCreated : zTreeonNodeCreated,
                onClick:zTreeClick
            }
            
        };
 
    function zTreeClick(event,treeId,treeNode){
   
    //var flag=treeNode.FLAG;
      //  alert(flag);
        var a=treeNode.id;
          //alert(a);
          a=a.replace("C","");
          
        //alert(a);
       var b=treeNode.FLAG;
         //alert(b);
         if(b==0){
         //var div=document.getElementById("add_gridTable");
         //div.style.visibility="visible";
         $("#add_gridTable").show();
           $("#edit_gridTable").show();
           $("#del_gridTable").show();
           
            jQuery("#gridTable").jqGrid('setGridParam',{
                url : "${request.contextPath}/list!list.action?voyageId="+a,
                page : 1
            });
             
            //jQuery("#gridTable").navGrid('setGridParam',{
              //  add:false
            //});
            jQuery("#gridTable").trigger('reloadGrid');
            jQuery("#gridPager").trigger('reloadGrid');
            
         }else{
         
           // var div=document.getElementById("add_gridTable");
           // div.style.visibility='hidden'
        	 //div.style.visibility='visible'
        	 //style.display="none"
        	 //style.display=""
            jQuery("#gridTable").jqGrid('setGridParam',{
                url : "${request.contextPath}/list!list.action?voyageId="+a,
                page : 1
            });
            $("#add_gridTable").hide();
            $("#edit_gridTable").hide();
            $("#del_gridTable").hide();
            $("#edit_gridSchedulingTable").hide();
            $("#del_gridSchedulingTable").hide();
            $("#add_gridSchedulingTable").hide();
            jQuery("#gridTable").trigger('reloadGrid');
            jQuery("#gridPager").trigger('reloadGrid');
            jQuery("#gridSchedulingTable").trigger('reloadGrid');
            jQuery("#gridSchedulingPager").trigger('reloadGrid');
            
        }
        }
        function zTreeonNodeCreated(event,treeId,treeNode){
        var treeObj=$.fn.zTree.getZTreeObj(treeId);
        var list=treeObj.getNodeByParam("level",'1');
        treeObj.expandNode(list,true,true,true);
     }

        jQuery(document).ready(function(){
            $.fn.zTree.init($("#shipTree"), setting);
        });
        
        function fillCategoryId(params,postdata){
        	var treeObj=$.fn.zTree.getZTreeObj("shipTree");
            
            var nodes=  treeObj.getSelectedNodes();

            var add_data=new Object();

            var a=nodes[0].id;

            a=a.replace("C","");

            add_data["voyageId"]=a;

            add_data["beanName"] = "tsm.TsmJobScheduling";
            
            return add_data;
        	
        	
        }
        

$(function(){
    $("#gridTable").jqGrid({
    //list表格获取地址
        //list表格数据获取地址
        url:'${request.contextPath}/list!list.action',
        //list表格编辑地址
        editurl :'${request.contextPath}/operator.action',
        datatype: "json",
        mtype:"POST",
        height: 200,
        width: 870,
       colNames:['作业编号','航次编码','作业代码','码头','抬头说明','箱量总计','备注','状态','创建人','创建日期','最后修改人','最后修改时间'],
        colModel:[
            {name:'jobId',jsonmap:'JOB_ID',index:'JOB_ID',editable:false,hidden:true},          
            {name:'voyageId',jsonmap:'VOYAGE_ID',index:'VOYAGE_ID',editable:false},     
            {name:'jobCode',jsonmap:'JOB_CODE',editable:true,index:'JOB_CODE'},      
            {name:'dock',jsonmap:'DOCK',editable:true,index:'DOCK'},
            {name:'jobTitle',jsonmap:'JOB_TITLE',editable:true,index:'JOB_TITLE',
            },
            {name:'totalVolumes',jsonmap:'TOTAL_VOLUMES',index:'TOTAL_VOLUMES',editable:true,
            },
            {name:'remark',jsonmap:'REMARK',index:'REMARK',editable:true},
            {name:'status',jsonmap:'STATUS',index:'STATUS',editable:false,hidden:true,
              
            },
            {name:'createdBy',jsonmap:'CREATED_BY',editable:false,hidden:true},
            {name:'createdDate',jsonmap:'CREATED_DATE',editable:false,hidden:true,
                editoptions :  {dataInit: function(element) {
                    $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                }}       
            },
            {name:'lastUpdBy',jsonmap:'LAST_UPD_BY',editable:false,hidden:true},
            {name:'lastUpdDate',jsonmap:'LAST_UPD_DATE',editable:false,hidden:true,
              editoptions :  {dataInit: function(element) {
                    $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                }}  
            }     
        ],
        sortname:'JOB_ID',
        sortorder:'ASC',
        viewrecords : true,
        gridview : true,
        rownumbers : true,
        rowNum : 20,
        altRows:true,
        rowList : [10,20,30],
        //onSelectRow:cellSelect,
        jsonReader : {
            page : "page.pageNo",
            total : "page.totalPages",
            records : "page.totalCount",
            root : "page.result",
            repeatitems : false,
            id : 'JOB_ID'
        },
        
        prmNames : {
            rows : "page.pageSize",
            page : "page.pageNo",
            sort : "page.orderBy",
            order : "page.order"
        },
        onCellSelect: function(id){
        	  
            jQuery("#gridSchedulingTable").jqGrid('setGridParam',{
                url : "${request.contextPath}/list!list.action?jobId="+id,
                page : 1 
            });
            $("#edit_gridSchedulingTable").show();
            $("#del_gridSchedulingTable").show();
            $("#add_gridSchedulingTable").show();
            jQuery("#gridSchedulingTable").trigger('reloadGrid');
            },
        
        loadBeforeSend : function(xhr,settings){
            //设置访问的list标签
            settings.data=settings.data+ "&gridKey=/list/operation#TsmJobScheduling";
            return true;
        },
        pager : "#gridPager",
        caption : "作业计划列表"
    }).navGrid('#gridPager',{
            add:true,
            edit:true,
            //editfunc:editVoyage,
            //addfunc:addVoyage,
            del:true, 
            //delfunc:delVoyage,
            search: false
    },{ 
        //edit
        //beforeSubmit:cellSelect,
        reloadAfterSubmit:true,
        closeAfterEdit:true,//新增完毕后关闭
        afterComplete:opertaionPrompt,//更新结束后提示信息
        onclickSubmit: fillCategoryId , //触发的事件
        //beforeSubmit:cellSelect
    },{
    //add
    	//beforeSubmit:cellSelect,
        reloadAfterSubmit : true,
        closeAfterAdd : true, //新增完毕后关闭
        afterComplete : opertaionPrompt,
        onclickSubmit: fillCategoryId
    },{
      //del
        reloadAfterSubmit : true, 
        closeAfterEdit : true,  //修改完毕后关闭
        afterComplete : opertaionPrompt, //更新结束后提示信息
        onclickSubmit: fillCategoryId 
        
    })
    initJqGridHideBtn();
});

$(function(){
 $("#time").datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat : 'yy-mm-dd'
        });
$("#editTime").datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat : 'yy-mm-dd'
        });


})


var addVoyage=function(){
    var treeObj=$.fn.zTree.getZTreeObj("shipTree");
    //alert(treeObj);
      var nodes=treeObj.getSelectedNodes();
    //alert(nodes);
    var a=nodes[0].FLAG;
    //alert(a);

    var reg=/^1$/;
   var isMatch=reg.test(a);
   //alert(isMatch);
   if(isMatch){
     alert("已起航，不可编辑");
   }else{
     var consoleDlg = $("#gridDialog");   
     var dialogButtonPanel = consoleDlg.siblings(".ui-dialog-buttonpane"); 
     consoleDlg.find("#jobCode").removeAttr().val("");
     consoleDlg.find("#jobTitle").removeAttr().val("");
     consoleDlg.find("#dock").removeAttr().val("");
     consoleDlg.find("#totalVolumes").removeAttr().val("");
     consoleDlg.find("#remark").removeAttr().val("");
     
     consoleDlg.dialog("option", "title", "新增作业计划").dialog("open"); 
 }
    
}
   $("#gridDialog").dialog({  
         autoOpen: false,      
         modal: true,    // 设置对话框为模态（modal）对话框  
         resizable: true,      
         width: 480,  
         buttons: {//为对话框添加按钮
         "确定":addUser,
         "取消":function() {$("#gridDialog").dialog("close")}
       }
     
});  
 function addUser(){
     var gd =$("#gridDialog");
     var jobCode=$.trim(gd.find("#jobCode").val());
      var jobTitle=$.trim(gd.find("#jobTitle").val());
       //alert(isMatch);
      var dock=$.trim(gd.find("#dock").val());
      var totalVolumes=$.trim(gd.find("#totalVolumes").val());
       var remark=$.trim(gd.find("#remark").val());
      //alert(remark);
      var treeObj=$.fn.zTree.getZTreeObj("shipTree");
    //alert(treeObj);
      var nodes=treeObj.getSelectedNodes();
    //alert(nodes);
    var id=nodes[0].id;
    
      id=id.replace("C","");
      //alert(id);  
     $.ajax({
            url: '${request.contextPath}/operator.action',
            type:'post',
            data:{'jobCode':jobCode,"jobTitle":jobTitle,"dock":dock,"totalVolumes":totalVolumes,"remark":remark,"oper":"add","beanName":"tsm.TsmJobScheduling","voyageId":id},
            dataType : 'json',
            success:function(result){
                alert(result.message);
                jQuery("#gridTable").trigger('reloadGrid');      
                $("#gridDialog").dialog("close")
            }
        });
     
       
 }  
 
 var editVoyage=function(){
    var treeObj=$.fn.zTree.getZTreeObj("shipTree");
    //alert(treeObj);
      var nodes=treeObj.getSelectedNodes();
    //alert(nodes);
    var a=nodes[0].FLAG;
   // alert(a);
    var reg=/^1$/;
   var isMatch=reg.test(a);
   //alert(isMatch);
   if(isMatch){
     alert("已起航，不可编辑");
   }else{
      var selectedId = $("#gridTable").jqGrid(
            "getGridParam", "selrow");
      var editJobCode=jQuery("#gridTable").jqGrid('getRowData',selectedId).jobCode;
      var editDock=jQuery("#gridTable").jqGrid('getRowData',selectedId).dock;
      var editJobTitle=jQuery("#gridTable").jqGrid('getRowData',selectedId).jobTitle;
      var editTotalVolumes=jQuery("#gridTable").jqGrid('getRowData',selectedId).totalVolumes;
      var editRemark=jQuery("#gridTable").jqGrid('getRowData',selectedId).remark;
            
     var consoleDlg = $("#editDialog");   
     var dialogButtonPanel = consoleDlg.siblings(".ui-dialog-buttonpane"); 
     
     consoleDlg.find("#editJobCode").removeAttr().val(editJobCode);
     consoleDlg.find("#editDock").removeAttr().val(editDock);
     consoleDlg.find("#editJobTitle").removeAttr().val(editJobTitle);
     consoleDlg.find("#editTotalVolumes").removeAttr().val(editTotalVolumes);
     consoleDlg.find("#editRemark").removeAttr().val(editRemark);
     consoleDlg.dialog("option", "title", "编辑作业计划").dialog("open"); 
 }
    
}
 

  $("#editDialog").dialog({  
         autoOpen: false,      
         modal: true,    // 设置对话框为模态（modal）对话框  
         resizable: true,      
         width: 480,  
    
         buttons: {//为对话框添加按钮
         "确定":editUser,
         "取消":function() {$("#editDialog").dialog("close")}
       }
     
});  
  
  function editUser(){
     var gd =$("#editDialog");
     var editJobCode=$.trim(gd.find("#editJobCode").val());
       var editDock=$.trim(gd.find("#editDock").val());
      var editJobTitle=$.trim(gd.find("#editJobTitle").val());
      var editTotalVolumes=$.trim(gd.find("#editTotalVolumes").val());
      var remark=$.trim(gd.find("#editRemark").val());
      //alert(remark);
      var treeObj=$.fn.zTree.getZTreeObj("shipTree");
    //alert(treeObj);
      var nodes=treeObj.getSelectedNodes();
    //alert(nodes);
    var id=nodes[0].id;
    
      id=id.replace("C","");
      //alert(id);  
      var selectedId = $("#gridTable").jqGrid("getGridParam", "selrow")
            var jobId=jQuery("#gridTable").jqGrid('getRowData',selectedId).jobId;
      
     $.ajax({
            url: '${request.contextPath}/operator.action',
            type:'post',
            data:{'jobCode':editJobCode,"dock":editDock,"jobTitle":editJobTitle,"totalVolumes":editTotalVolumes,"remark":remark,"oper":"edit","beanName":"tsm.TsmJobScheduling","voyageId":id,"id":jobId},
            dataType : 'json',
            success:function(result){
                alert(result.message);
                jQuery("#gridTable").trigger('reloadGrid');      
                $("#editDialog").dialog("close")
            }
        });
     
      
 }  
 
 var delVoyage=function(){
      var treeObj=$.fn.zTree.getZTreeObj("shipTree");
    //alert(treeObj);
      var nodes=treeObj.getSelectedNodes();
    //alert(nodes);
    var a=nodes[0].FLAG;
    //alert(a);
    var reg=/^1$/;
   var isMatch=reg.test(a);
   //alert(isMatch);
   if(isMatch){
     alert("已起航，不可删除");
   }else{
      var consoleDlg = $("#delDialog");   
      var dialogButtonPanel = consoleDlg.siblings(".ui-dialog-buttonpane"); 
      consoleDlg.dialog("option", "title", "确定删除记录作业计划？").dialog("open"); 

   }
 
 }
 $("#delDialog").dialog({  
         autoOpen: false,      
         modal: true,    // 设置对话框为模态（modal）对话框  
         resizable: true,      
         width: 480,  
         buttons: {//为对话框添加按钮
         "确定":delUser,
         "取消":function() {$("#delDialog").dialog("close")}
       }
     
});
 function delUser(){
      var selectedId = $("#gridTable").jqGrid(
            "getGridParam", "selrow");
          $.ajax({
            url: '${request.contextPath}/operator.action',
            type:'post',
            data:{"oper":"del","beanName":"tsm.TsmJobScheduling","id":selectedId},
            dataType : 'json',
            success:function(request){
            alert(request.message);
                jQuery("#gridTable").trigger('reloadGrid');      
                $("#delDialog").dialog("close")
            }
        }); 
      
 }
 
 
 
 function fillSchedulingDtlId(params,postdata){
	 var selectedId = $("#gridTable").jqGrid(
	            "getGridParam", "selrow");
     var add_data=new Object();
     add_data["jobId"]=selectedId;
     add_data["status"]='1';
     add_data["beanName"] = "tsm.TsmJobSchedulingDtl";
     
     return add_data;
	 
 }
 
 
 $(function(){
    $("#gridSchedulingTable").jqGrid({
    //list表格获取地址
        //list表格数据获取地址
        url:'${request.contextPath}/list!list.action',
        //list表格编辑地址
        editurl :'${request.contextPath}/operator.action',
        datatype: "json",
        mtype:"POST",
        height: 200,
        width: 870,
        colNames:['作业明细编号','作业编号','客户号','单号','柜号','柜型','封号','目的地','卸货地','装卸标志','状态','创建人','创建日期','最后修改人','最后修改时间'],
        colModel:[
            {name:'jobDtlId',jsonmap:'JOB_DTL_ID',index:'JOB_DTL_ID',editable:false,hidden:true},          
            {name:'jobId',jsonmap:'JOB_ID',index:'JOB_ID',editable:false,hidden:true},     
            {name:'customerId',jsonmap:'CUSTOMER_ID',editable:true,index:'CUSTOMER_ID'},      
            {name:'orderNo',jsonmap:'ORDER_NO',editable:true,index:'ORDER_NO'},
            {name:'containerNo',jsonmap:'CONTAINER_NO',editable:true,index:'CONTAINER_NO'},
            {name:'containerType',jsonmap:'CONTAINER_TYPE',editable:true,index:'CONTAINER_TYPE'},
            {name:'sealNo',jsonmap:'SEAL_NO',editable:true,index:'SEAL_NO'},
            {name:'destinationPort',jsonmap:'DESTINATION_PORT',editable:true,index:'DESTINATION_PORT'},
            {name:'dischargePort',jsonmap:'DISCHARGE_PORT',editable:true,index:'DISCHARGE_PORT'},
            {name:'handlingFlag',jsonmap:'HANDLING_FLAG',editable:true,index:'HANDLING_FLAG'},
            {name:'status',jsonmap:'STATUS',index:'STATUS',editable:false,hidden:true},
            {name:'createdBy',jsonmap:'CREATED_BY',editable:false,hidden:true},
            {name:'createdDate',jsonmap:'CREATED_DATE',editable:false,hidden:true,
                editoptions :  {dataInit: function(element) {
                    $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                }}       
            },
            {name:'lastUpdBy',jsonmap:'LAST_UPD_BY',editable:false,hidden:true},
            {name:'lastUpdDate',jsonmap:'LAST_UPD_DATE',editable:false,hidden:true,
              editoptions :  {dataInit: function(element) {
                    $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                }}  
            }     
        ],
        sortname:'LAST_UPD_DATE',
        sortorder:'ASC',
        viewrecords : true,
        gridview : true,
        rownumbers : true,
        rowNum : 20,
        altRows:true,
        rowList : [10,20,30],
        //onSelectRow:cellSelect,
        jsonReader : {
            page : "page.pageNo",
            total : "page.totalPages",
            records : "page.totalCount",
            root : "page.result",
            repeatitems : false,
            id : 'JOB_DTL_ID'
        },
        
        
        prmNames : {
            rows : "page.pageSize",
            page : "page.pageNo",
            sort : "page.orderBy",
            order : "page.order"
        },
        loadBeforeSend : function(xhr,settings){
            //设置访问的list标签
            settings.data=settings.data+ "&gridKey=/list/operation#TsmJobSchedulingDtl";
            return true;
        },
        pager : "#gridSchedulingPager",
        caption : "作业计划明细列表"
    }).navGrid("#gridSchedulingPager",{
            edit:true,
            //editfunc:editSelect,
            add:true, 
            //addfunc:addVoyage,
            del:true, 
            //delfunc:selectDel,
            search: false
    },{ 
        //edit
        //beforeSubmit:cellSelect,
        reloadAfterSubmit:true,
        closeAfterEdit:true,//新增完毕后关闭
        afterComplete:opertaionPrompt,//更新结束后提示信息
        onclickSubmit: fillSchedulingDtlId  //触发的事件
    },{
    //add
        reloadAfterSubmit : true,
        closeAfterAdd : true, //新增完毕后关闭
        afterComplete : opertaionPrompt,
        onclickSubmit: fillSchedulingDtlId
    },{
      //del
        reloadAfterSubmit : true, 
        closeAfterEdit : true,  //修改完毕后关闭
        afterComplete : opertaionPrompt, //更新结束后提示信息
        onclickSubmit: fillSchedulingDtlId,    
        
    });
      
    initJqGridHideDtlBtn();
    
   
});
 
 
 
</#macro>

<#macro main>
  <div id="treediv" class="ui-widget-content ui-corner-all" style="border-color:Silver;margin:30px 10px 20px -30px;float:left;width:250px;">
           <ul id="shipTree" class="ztree"></ul>
  </div>
  <div id="detaildiv" style="background-color:Navy;margin:30px 10px 20px 0px;float:left;width:200px;">
           <table id="gridTable"></table>
           <div id="gridPager"></div>
  </div>
  <div id="gridDialog" style="visibility:hidden">  
                <form id="consoleForm">  
                    <input type="hidden" id="selectId" />  
                    <table class="formTable" id="dialogId">  
                        <tr>  
                            <th><span class="ui-widget-header">作业代码</span></th>  
                            <td>  
                                <input type="text" class="textField" id="jobCode" name="jobCode" />  
                            </td>  
                            
                        </tr>
                        <tr>
                        <th><span class="ui-widget-header">码头</span></th>  
                            <td>  
                                <input type="text" class="textField" id="dock" name="dock" />  
                            </td>   
                        </tr>  
                        <tr>
                        <th><span class="ui-widget-header">抬头说明</span></th>  
                            <td>  
                                <input type="text" class="textField" id="jobTitle" name="jobTitle" />  
                            </td>   
                        </tr>     
                        <tr>
                        <th><span class="ui-widget-header">箱量总计</span></th>  
                            <td>  
                                <input type="text" class="textField" id="totalVolumes" name="totalVolumes" />  
                            </td>   
                        </tr>  
                        <tr>
                        <th><span class="ui-widget-header">备注</span></th>  
                            <td>  
                                <input type="text" class="textField" id="remark" name="remark" />  
                            </td>   
                        </tr>  
                    </table>  
                </form>  
            </div>  
      
    
    </div>
    <div id="editDialog" style="visibility:hidden">  
                <form id="consoleForm">  
                    <input type="hidden" id="selectId" />  
                    <table class="formTable" id="dialogId">  
                        <tr>  
                            <th><span class="ui-widget-header">作业代码</span></th>  
                            <td>  
                                <input type="text" class="textField" id="editJobCode" name="editJobCode" />  
                            </td>  
                        </tr>
                        <tr>
                        <th><span class="ui-widget-header">码头</span></th>  
                            <td>  
                                <input type="text" class="textField" id="editDock" name="editDock" />  
                            </td>   
                        </tr>  
                        <tr>
                        <th><span class="ui-widget-header">抬头说明</span></th>  
                            <td>  
                                <input type="text" class="textField" id="editJobTitle" name="editJobTitle" />  
                            </td>   
                        </tr> 
                        <tr>
                        <th><span class="ui-widget-header">箱量总计</span></th>  
                            <td>  
                                <input type="text" class="textField" id="editTotalVolumes" name="editTotalVolumes" />  
                            </td>   
                        </tr>      
                        <tr>
                        <th><span class="ui-widget-header">备注</span></th>  
                            <td>  
                                <input type="text" class="textField" id="editRemark" name="editRemark" />  
                            </td>   
                        </tr>  
                    </table>  
                </form>  
            </div>  
      
    
    </div>
    <div id="delDialog" style="visibility:hidden">
    </div>
    <div id="schedulingDiv" style="background-color:Navy;margin:-185px 0px 0px 456px;float:left;width:200px;">
           <table id="gridSchedulingTable"></table>
           <div id="gridSchedulingPager"></div>
  </div>
</#macro>
        
        
        
        
        
